﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using PowerCreator.LMS.User.Entity;
public partial class sysadmin_CountManager_ProjectDetailClass :PowerCreator.LMS.Web.Base.BasePage
{
    PowerCreator.LMS.ViewQuery.ViewQuery opViewQuery = new PowerCreator.LMS.ViewQuery.ViewQuery();
    PowerCreator.LMS.Web.User.User opUser = new PowerCreator.LMS.Web.User.User();
    PowerCreator.LMS.Web.Project.NewProjectPlan opProjectPlan = new PowerCreator.LMS.Web.Project.NewProjectPlan();

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            string classid = Request.QueryString["ClassID"].ToString();
            ViewState["ClassID"] = classid;

            InitPage();
            string search = GetSearch();
            BinderPager(search);
            BinderRPT(search, 1);
        }
    }

    protected override void InitPage()
    {
        base.InitPage();
    }
    private string GetSearch()
    {
        string search = string.Format("select * from VM_Sys_ProjectUser where ClassID={0} ", ViewState["ClassID"]);
        return search;
    }
    private void BinderPager(string search)
    {
        AspNetPager1.PageSize = LMSPageSize;
        AspNetPager1.RecordCount = opViewQuery.Count(search);
        
    }
    private void BinderRPT(string search,int pageIndex)
    {
        DataTable dt = opViewQuery.Query(search, LMSPageSize, pageIndex);

        dt.Columns.Add("UserName1");
        dt.Columns.Add("UserTypeName1");
        dt.Columns.Add("UserRealName1");
        dt.Columns.Add("ProjectStateName1");    //方案状态
        for (int i = 0; i < dt.Rows.Count; i++)
        {
            VOTUser voUser = opUser.LoadUser(int.Parse(dt.Rows[i]["UserID"].ToString()));
            if (voUser != null)
            {
                dt.Rows[i]["UserName1"] = voUser.UserName;
                if (voUser.UserType == 0)
                {
                    dt.Rows[i]["UserTypeName1"] = "学生";
                    VOTStudent voStudent = opUser.LoadStudentByUserID(voUser.UserId);
                    if (voStudent != null)
                        dt.Rows[i]["UserRealName1"] = voStudent.StudentName;
                }
                else if (voUser.UserType == 1 || voUser.UserType == 2)
                {
                    dt.Rows[i]["UserTypeName1"] = "教师";
                    VOTTeacher voTeacher = opUser.LoadTteacherByUserID(voUser.UserId);
                    if (voTeacher != null)
                        dt.Rows[i]["UserRealName1"] = voTeacher.TeacherName;
                }
                else
                    dt.Rows[i]["UserTypeName1"] = "未知类型";
            }
            string s1 = string.Format("FKSpplogTrainclaID = {0} and FKSpplogUserID = {1}", ViewState["ClassID"], dt.Rows[i]["UserID"]);

            DataTable dt1 = opProjectPlan.QueryProjectPlan(s1, 1, 1);
            if (dt1.Rows.Count == 1)
            {
                dt.Rows[i]["ProjectStateName1"] = opProjectPlan.GetProjectPlanByState(int.Parse(dt1.Rows[0]["SpplogState"].ToString()), PowerCreator.LMS.Web.Project.ProjectPlan.ProjectPlan);
            }
        }
    }

    protected void AspNetPager1_PageChanged(object sender, EventArgs e)
    {
        string search = GetSearch();
        BinderRPT(search, AspNetPager1.CurrentPageIndex);
    }
}
